home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / EGAVGA.SWG / 0023_READLNXY.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  93 lines

  1. {
  2. ERIC MILLER
  3.  
  4. > My question is this: In TP, the outtextxy is supposed to change the
  5. > CP (current pointer) to the location given in x,y. When you execute a
  6. > readln after a outtextxy or even and outtext, the program always
  7. > starts at 0,0.. Is there a way to set the CP where the readln will
  8. > recognize it?
  9.  
  10.   Here's a demo of a procedure called ReadlnXY; it reads
  11.   a string in graphics mode using BGI support.
  12. }
  13.  
  14. PROGRAM Graphics_Readln;
  15.  
  16. Uses
  17.   Crt, Graph;
  18.  
  19. PROCEDURE ReadlnXY(X, Y: Integer; VAR S: String);
  20. VAR
  21.   Ch       : Char;    { key from keyboard }
  22.   Done     : boolean; { our flag for quiting }
  23.   CurColor : word;    { color to write text in }
  24.   OldX     : Integer; { old x }
  25.  
  26. BEGIN
  27.   S := '';
  28.   CurColor := GetColor;
  29.   MoveTo(X, Y);
  30.   Done := False;
  31.   WHILE NOT Done  DO
  32.   BEGIN
  33.     Ch := Readkey;  { get a single key }
  34.  
  35.     CASE Ch of
  36.       #0  : { extra key - two chars - let's ignore them }
  37.         Ch := Readkey;
  38.  
  39.       #13 : { return key }
  40.         Done := true; { we got our string, let's go }
  41.  
  42.       #32..#126:  { ASCII 32 (space) through 126 (tilde) }
  43.         BEGIN
  44.           OutText(Ch);
  45.           S := Concat(S, Ch);
  46.         END;
  47.  
  48.       #8  : IF Length(S) > 0 THEN
  49.         BEGIN
  50.           { move back to last character }
  51.           OldX := GetX - TextHeight(S[Length(S)]);
  52.           MoveTo(OldX, GetY);
  53.           { over write last character }
  54.           SetColor(0);
  55.           OutText(S[Length(S)]);
  56.           SetColor(CurColor);
  57.           MoveTo(OldX, GetY);
  58.           { remove last character from the string }
  59.           Delete(S, Length(S), 1);
  60.         END;
  61.  
  62.     END;
  63.   END;
  64. END; { ReadlnXY }
  65.  
  66.  
  67.  
  68. VAR
  69.   GraphMode, GraphDriver: Integer;
  70.   Name, PathToDriver: String;
  71.  
  72. BEGIN
  73.  
  74.   GraphDriver := VGA;            { VGA }
  75.   GraphMode := VGAHi;            { 640x480x16 }
  76.   PathToDriver := 'D:\BP\BGI';   { path to EGAVGA.BGI }
  77.      { you can make this program work with EGA 640x350x16 -
  78.        it  requires 640 wide and 16 colors to work for this
  79.        example, but ReadlnXY should work in any graphics mode }
  80.   InitGraph(GraphDriver, GraphMode, PathToDriver); { set graphics mode }
  81.  
  82.   SetTextStyle(DefaultFont, HorizDir, 2);
  83.  
  84.   SetColor(12);
  85.  
  86.   OutTextXY(63, 63, 'Please enter your name: ');
  87.   SetColor(13);
  88.   ReadlnXY(63 ,95, Name);
  89.   CloseGraph;
  90.   Write('The name you entered was: ');
  91.   Writeln(Name);
  92. END.
  93.